package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import com.easonji.common.util.JsonUtils;
import com.easonji.common.page.PageInfo;
import com.easonji.common.util.StringUtils;
import com.easonji.common.base.query.BaseQuery;
import com.easonji.common.factory.PageFactory;

import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;
import com.alibaba.fastjson.JSONObject;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
public class ${table.serviceImplName} extends ${superServiceImplClass}<${entity}> implements ${table.serviceName} {

    @Resource
    private ${entity}Mapper ${table.entityPath}Mapper;

    @Override
    protected JSONObject warp2Json(${entity} ${table.entityPath}) {
       JSONObject result = JsonUtils.parseObject(${table.entityPath});

       return result;
    }


    @Override
    public Object queryList(BaseQuery baseQuery){

        // 分页信息
        Page<${entity}> page = new PageFactory<${entity}>().defaultPage();
        // 查询条件
        Wrapper<${entity}> wrapper = new EntityWrapper<>();

        List<${entity}> ${table.entityPath}s = ${table.entityPath}Mapper.selectPage(page, wrapper);

        return new PageInfo(warp(${table.entityPath}s), page.getTotal());
    }

    @Override
    public Object queryRowById(Integer ${table.fields[0].propertyName}) {
        ${entity} ${table.entityPath} = ${table.entityPath}Mapper.selectById(${table.fields[0].propertyName});
        return warp(${table.entityPath});
    }

    @Override
    public Integer save(${entity} ${table.entityPath}) {

        return ${table.entityPath}Mapper.insert(${table.entityPath});
    }

    @Override
    public Integer update(${entity} ${table.entityPath}Form) {
        ${entity} ${table.entityPath} = new ${entity}();
        BeanUtils.copyProperties(${table.entityPath}Form,${table.entityPath});
        return ${table.entityPath}Mapper.updateById(${table.entityPath});
    }

    @Override
    public Integer delete(Integer ${table.fields[0].propertyName}) {
        Wrapper<${entity}> wrapper = new EntityWrapper<>();
        wrapper.eq("${table.fields[0].name}", ${table.fields[0].propertyName});
        return ${table.entityPath}Mapper.delete(wrapper);
    }

}
